$(function() {
    // 添加点击事件
    $('input').on('click', function() {
        localStorage.setItem('E', getE());
        localStorage.setItem('I', getI());
        localStorage.setItem('S', getS());
        localStorage.setItem('N', getN());
        localStorage.setItem('T', getT());
        localStorage.setItem('F', getF());
        localStorage.setItem('J', getJ());
        localStorage.setItem('P', getP());
        console.log(getMbti());
    })

    $('.submit a').on('click', function() {
        if (getMbti() === "ISTJ" && getLength() >= 198) {
            $('.submit a').prop('href', 'report_mbti/01mbti_istj.html')
        } else if (getMbti() === "ISFJ" && getLength() >= 198) {
            $('.submit a').prop('href', 'report_mbti/02mbti_isfj.html')
        } else if (getMbti() === "ESTJ" && getLength() >= 198) {
            $('.submit a').prop('href', 'report_mbti/03mbti_estj.html')
        } else if (getMbti() === "ESFJ" && getLength() >= 198) {
            $('.submit a').prop('href', 'report_mbti/04mbti_esfj.html')
        } else if (getMbti() === "ISTP" && getLength() >= 198) {
            $('.submit a').prop('href', 'report_mbti/05mbti_istp.html')
        } else if (getMbti() === "ISFP" && getLength() >= 198) {
            $('.submit a').prop('href', 'report_mbti/06mbti_isfp.html')
        } else if (getMbti() === "ESTP" && getLength() >= 198) {
            $('.submit a').prop('href', 'report_mbti/07mbti_estp.html')
        } else if (getMbti() === "ESFP" && getLength() >= 198) {
            $('.submit a').prop('href', 'report_mbti/08mbti_esfp.html')
        } else if (getMbti() === "INFJ" && getLength() >= 198) {
            $('.submit a').prop('href', 'report_mbti/09mbti_infj.html')
        } else if (getMbti() === "INFP" && getLength() >= 198) {
            $('.submit a').prop('href', 'report_mbti/10mbti_infp.html')
        } else if (getMbti() === "ENFJ" && getLength() >= 198) {
            $('.submit a').prop('href', 'report_mbti/11mbti_enfj.html')
        } else if (getMbti() === "ENFP" && getLength() >= 198) {
            $('.submit a').prop('href', 'report_mbti/12mbti_enfp.html')
        } else if (getMbti() === "INTJ" && getLength() >= 198) {
            $('.submit a').prop('href', 'report_mbti/13mbti_intj.html')
        } else if (getMbti() === "INTP" && getLength() >= 198) {
            $('.submit a').prop('href', 'report_mbti/14mbti_intp.html')
        } else if (getMbti() === "ENTJ" && getLength() >= 198) {
            $('.submit a').prop('href', 'report_mbti/15mbti_entj.html')
        } else if (getMbti() === "ENTP" && getLength() >= 198) {
            $('.submit a').prop('href', 'report_mbti/16mbti_entp.html')
        } else {
            alert('提交失败,您有未完成的题目')
        }
        //点击结尾
    })

    //检验
    // console.log($('.e_kind').length);
    // console.log($('.i_kind').length);
    // console.log($('.s_kind').length);
    // console.log($('.n_kind').length);
    // console.log($('.t_kind').length);
    // console.log($('.f_kind').length);
    // console.log($('.j_kind').length);
    // console.log($('.p_kind').length);



    //计数，函数封装
    function getE() {
        var esum = 0
        $.each($('.e_kind'), function(i, ele) {
            if ($(ele).prop('checked')) {
                esum++
            }
        })
        return esum
    }

    function getI() {
        var isum = 0
        $.each($('.i_kind'), function(i, ele) {
            if ($(ele).prop('checked')) {
                isum++
            }
        })
        return isum
    }

    function getS() {
        var ssum = 0
        $.each($('.s_kind'), function(i, ele) {
            if ($(ele).prop('checked')) {
                ssum++
            }
        })
        return ssum
    }

    function getN() {
        var nsum = 0
        $.each($('.n_kind'), function(i, ele) {
            if ($(ele).prop('checked')) {
                nsum++
            }
        })
        return nsum
    }

    function getT() {
        var tsum = 0
        $.each($('.t_kind'), function(i, ele) {
            if ($(ele).prop('checked')) {
                tsum++
            }
        })
        return tsum
    }

    function getF() {
        var fsum = 0
        $.each($('.f_kind'), function(i, ele) {
            if ($(ele).prop('checked')) {
                fsum++
            }
        })
        return fsum
    }

    function getJ() {
        var jsum = 0
        $.each($('.j_kind'), function(i, ele) {
            if ($(ele).prop('checked')) {
                jsum++
            }
        })
        return jsum
    }

    function getP() {
        var psum = 0
        $.each($('.p_kind'), function(i, ele) {
            if ($(ele).prop('checked')) {
                psum++
            }
        })
        return psum
    }
    //93
    function getLength() {
        var length = $("input[type='radio']:checked").length //求长度，也就是被选中的个数
        return length
    }
    //mbti
    function getMbti() {
        if (getE() <= getI()) {
            var a = 'I'
        } else {
            var a = 'E'
        }
        if (getS() <= getN()) {
            var b = 'N'
        } else {
            var b = 'S'
        }
        if (getT() <= getF()) {
            var c = 'F'
        } else {
            var c = 'T'
        }
        if (getJ() <= getP()) {
            var d = 'P'
        } else {
            var d = 'J'
        }
        var mbti = a + b + c + d
        return mbti
    }

    // 取值
    var e = localStorage.getItem('E');
    var i = localStorage.getItem('I');
    var s = localStorage.getItem('S');
    var n = localStorage.getItem('N');
    var t = localStorage.getItem('T');
    var f = localStorage.getItem('F');
    var j = localStorage.getItem('J');
    var p = localStorage.getItem('P');
    // 图形
    var myChart = echarts.init(document.querySelector('.youtype2_img'));
    var option = {
        dataset: {
            source: [
                ['score', 'amount', 'product'],
                [89.3, e, 'E外向'],
                [57.1, i, 'I内向'],
                [74.4, s, 'S实觉'],
                [50.1, n, 'N直觉'],
                [89.7, t, 'T思维'],
                [68.1, f, 'F情感'],
                [19.6, j, 'J判断'],
                [10.6, p, 'P知觉'],
            ]
        },
        grid: { containLabel: true },
        xAxis: { name: '' },
        yAxis: { type: 'category' },
        visualMap: {
            orient: 'horizontal',
            left: 'center',
            min: 10,
            max: 100,
            // text: ['High Score', 'Low Score'],
            // Map the score column to color
            dimension: 0,
            inRange: {
                color: ['#65B581', '#FFCE34', '#FD665F']
            }
        },
        series: [{
            type: 'bar',
            encode: {
                // Map the "amount" column to X axis.
                x: 'amount',
                // Map the "product" column to Y axis
                y: 'product'
            }
        }]
    };
    myChart.setOption(option);

    //入口
})